<template>
    <div class="hello">
        <el-form>
            <div style="width: 350px">
                <el-form-item label-width="30" prop="fileList">
                    <el-upload
                            style="margin-top: 20px;"
                            ref="upload"
                            :file-list="editNotice.fileList"
                            drag
                            :limit="2"
                            :multiple="false"
                            :show-file-list="true"
                            action="/api"
                            :data="uploadData"
                            :on-success="successCall"
                            :on-remove="uploadRemove"
                            :on-change="uploadFileChange"
                            :auto-upload="false">
                        <i class="el-icon-upload"></i>
                        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                        <!--<div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>-->
                    </el-upload>
                </el-form-item>
            </div>
        </el-form>

    </div>
</template>

<script>
    export default {
        data() {
            return {
                editNotice: {
                  /*  id: null,
                    title: '',
                    filePath: '',
                    order: null,
                    type: null,
                    endTime: null,*/
                    fileList: []
                },
                uploadData: {Data: null},
                //uploadIsChange: false,
            };
        },
        methods: {
            uploadRemove() {
                this.editNotice.fileList = [];
            },
            uploadFileChange(file) {
                //this.uploadIsChange = true;
                //this.editNotice.fileList = [];
                this.$refs.upload.uploadFiles = this.editNotice.fileList;
                this.editNotice.fileList.push(file);
            },
            successCall(response) {
                let res = this.decrypt(response);
                if (!res) {
                    this.$message.error("网络错误");
                }
                if (res.E) {
                    this.$message.error(res.E);
                } else {
                    this.$message.success("保存成功");
                    this.$router.push('/notice/index?type=0')
                }
            },

        }
    }
</script>
